# Copyright (c) 2008 Alvin Wang http://cloudwizard.com/
# License New BSD
# See README for additional information
"""
Google Cloud Support

Appengine - template the app.yaml
application
Version - auto-increment

Cloud auth
    Username
    password
Machine
    Application 
    Version
    
Password will not be passed in - just execute it and let cookie take care of it,

 ~/google_appengine/appcfg.py --email=alvinwang@gmail.com   update 2tiercommission

"""

from cloudwizard.cloud import Cloud
from cloudwizard.config import Config


class Aws(Cloud):
    """
    
    """
    cloud_name = "Google"
    cloud_abbrev = "google"

    def script_auth(self, username='default'):
        """Ask for Access Id, Secrey Key, and default Key Pair 
        """
        self.cloud_auth = Config( cloud_abbrev=self.cloud_abbrev, type='user',
            autoload=False) 
        
        self.cloud_auth.prompt(question="Please enter your Google Id", varname="username")
            
        self.cloud_auth.prompt(question="Please enter your Google password", varname="password")
         
        username = self.cloud_auth.prompt(question="What name do you want to save this set of credentials under?",
            default='default',  varname="filename")

        self.cloud_auth.write_config( config_name=username)

    def script_machine(self, machine='default'):
        """Ask for Access Id, Secrey Key, and default Key Pair 
        """
        self.cloud_auth = Config( cloud_abbrev=self.cloud_abbrev, type='user',
            autoload=False) 
        
        self.cloud_auth.prompt(question="Please enter your Google Id", varname="username")
            
        self.cloud_auth.prompt(question="Please enter your Google password", varname="password")

        self.cloud_auth.prompt(question="What is the path to AppEngine?", 
            varname="apppath")

        self.cloud_auth.prompt(question="What is the App name?", 
            varname="appname")
            
        servername = self.cloud_auth.prompt(question="What machine would you like to save this under?",
            default='default', servername="username")
        # Add more stuff
        # get a default key or create it if necessary
        # 
        self.cloud_auth.write_config( config_name=servername)
        
    def get_service(self, service=None, **args):
        """return a Google service"""
        # could use lambda but it is more painful
        if service == "platform":
            return AppEngine( auth=self.cloud_auth)

